/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-09-04     armink       the first version
 */

#include <ulog.h>

#ifdef ULOG_BACKEND_USING_CONSOLE

static struct ulog_backend console;
static signed short (*ulog_console)(char * data, unsigned short len);
static void(*ulog_console_flush)(void);

static void ulog_console_backend_output(struct ulog_backend *backend, rt_uint32_t level, const char *tag, rt_bool_t is_raw,
        const char *log, size_t len);
static void ulog_console_backend_fush(struct ulog_backend *backend);

void ulog_console_backend_output(struct ulog_backend *backend, rt_uint32_t level, const char *tag, rt_bool_t is_raw,
        const char *log, size_t len)
{
	ulog_console((char *)log, len);
}

void ulog_console_backend_fush(struct ulog_backend *backend)
{
	if (ulog_console_flush != NULL)
		ulog_console_flush();
}

int ulog_console_backend_init(signed short (*console_callback)(char *, unsigned short), void (*console_flush)(void))
{
    ulog_console = console_callback;
    ulog_console_flush = console_flush;
    console.output = ulog_console_backend_output;
    console.flush = ulog_console_backend_fush;
    ulog_backend_register(&console, "console", RT_TRUE);

    return 0;
}
INIT_PREV_EXPORT(ulog_console_backend_init);

#endif /* ULOG_BACKEND_USING_CONSOLE */
